#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;  // price, volumn
typedef long long ll;
const int N = 106;
int v, n;
pi arr[N];
int solve() {
  sort(arr, arr+n, [](pi a, pi b) {
        return a.first > b.first;
      });
  ll ans = 0;
  for(int i=0; i<n; ++i) {
    auto pri=arr[i].first, vol=arr[i].second;
    if(v>=vol) {
      ans += 1LL*pri*vol;
      v -= vol;
    }
    else {
      ans += 1LL * pri * v;
      break;
    }
  }
  cout<<ans<<'\n';
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  while(cin>>v) {
    if(v==0) break;
    cin>>n;
    for(int i=0; i<n; ++i) cin>>arr[i].first>>arr[i].second;
    solve();
  }
  return 0;
}

